<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-06-04 13:56:40
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2024-06-14 14:07:10
 * @FilePath: /consult-patient-vue3-ts/src/views/Room/components/RoomAction.vue
 * @Description: 
 * 
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
-->
<script setup lang="ts">
import {defineProps,ref,defineEmits} from 'vue'
import type { Image } from '@/types/consult'
import type { UploaderAfterRead } from 'vant/lib/uploader/types';
import { uploadImage } from '@/services/consult'

defineProps<{
  disabled: boolean
}>()
const emit = defineEmits<{
  (e: 'send-text', text: string): void
  (e: 'send-image', img: Image): void
}>()
const text = ref('')
const sendText = () => {
  emit('send-text', text.value)
  text.value = ''
}
const sendImage:UploaderAfterRead = async (fileObj) => {
  if(Array.isArray(fileObj))return
  if(!fileObj.file)return
  const res = await uploadImage(fileObj.file)
  //发送图片
  emit('send-image', res.data)
}
</script>

<template>
    <div class="room-action">
        <van-field type="text" :disabled="disabled" class="input" :border="false" placeholder="问医生" autocomplete="off" @keyup.enter="sendText" v-model="text"></van-field>
        <van-uploader :preview-image="false" :disabled="disabled" :after-read="sendImage">
            <cp-icon name="consult-img" />
        </van-uploader>
    </div>
</template>

<style lang="scss" scoped>
.room-action {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 60px;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 1;
    box-sizing: border-box;

    .input {
        background-color: var(--cp-bg);
        border: none;
        border-radius: 25px;
        margin-right: 10px;
        padding: 8px 15px;
    }

    .cp-icon {
        width: 24px;
        height: 24px;
    }
}
</style>